import dva from 'dva';
import { render } from 'react-dom';
import Loadable from 'react-loadable';

import createHistory from 'history/createBrowserHistory';
//import createLoading from 'dva-loading';
import './index.css';


const preloadedState = window.__PRELOADED_STATE__ || {};
delete window.__PRELOADED_STATE__;

// 1. Initialize
const app = dva({
  history: createHistory(),
  initialState: preloadedState
});

app.use(require('dva-logger')());

// 2. Plugins
//app.use(createLoading());
// app.use({});

// 3. Model
// app.model(require('./models/example').default);

// 4. Router
app.router(require('../router').default);

// 5. Start
Loadable.preloadReady().then(() => {
  const App = app.start();
  render(
    <App />,
    document.getElementById('root')
  );
});

export default app;